import {
  create,
  deleteById,
  listByPage,
  listLatestArticles,
  update
} from "@/services/articlesettingApi.js";

export default {
  namespace: "articlesetting",

  state: {
    data: {
      list: [],
      pagination: {}
    }
  },

  effects: {
    *create({ payload }, { call, put }) {
      const response = yield call(create, payload);
      return response;
    },

    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      return response;
    },

    *deleteById({ payload }, { call, put }) {
      const response = yield call(deleteById, payload);
      return response;
    },

    *listLatestArticles({ payload }, { call, put }) {
      const response = yield call(listLatestArticles, payload);
      return response;
    },

    *listByPage({ payload }, { call, put }) {
      const response = yield call(listByPage, payload);
      yield put({
        type: "cb4listByPage",
        payload: response
      });
    }
  },

  reducers: {
    cb4listByPage(state, action) {
      return {
        ...state,
        data: action.payload.data
      };
    }
  }
};
